// 方式一
function longestPalindrome(s) {
  let ret = "";
  for (let n = 0; n < s.length; n++) {
    for (let m = n + 1; m < s.length + 1; m++) {
      const temp = s.substring(n, m);
      const palindrome = isPalindrome(temp);
      if (palindrome && ret.length < temp.length) {
        ret = temp;
      }
    }
  }

  function isPalindrome(x) {
    for (let i = 0, len = x.length; i < len / 2; i++) {
      if (x[i] != x[len - i - 1]) return false;
    }
    return true;
  }
  return ret;
}

// 获取字符串的所有子串;
function getChildString(string) {
  let ret = [];
  for (let n = 0; n < string.length; n++) {
    for (let m = n + 1; m < string.length + 1; m++) {
      ret.push(string.substring(n, m));
    }
  }
  return ret;
}

console.log(getChildString("2212"));
console.log(longestPalindrome("2212"));
